import os
from langchain_community.chat_models import ChatZhipuAI 
from dotenv import load_dotenv, find_dotenv

_ = load_dotenv(find_dotenv())
model = os.environ.get('model')
if model is None:
    raise ValueError("model is not set in the .env file")

llm = ChatZhipuAI(model=model,
                  temperature=0.9,                 
        )

from datetime import datetime
def _get_date():
    now = datetime.now()
    return now.strftime("%Y年%m月%d日")

from langchain.prompts.prompt import PromptTemplate
prompt = PromptTemplate(
    template="""写一篇{domain}领域相关的新闻稿，
        时间是{date}，
        字数在200-300字之间。""", 
    input_variables=["domain"],
    partial_variables={"date": _get_date}
)

input_domain = input("请输入您感兴趣的领域：")
result = llm.invoke(prompt.format(domain=input_domain))
print(f"\n生成结果：\n{result.content}")